<?php
namespace Admin\Controller;
use Gy_Library\DBCont;
use Gy_Library\GyListController;

class PersonInfoController extends GyListController{

    public function index(){
        $map = [];
        $news_model = D(CONTROLLER_NAME);
        $count = $news_model->getListForCount($map);
        $per_page = C('ADMIN_PER_PAGE_NUM', null, false);
        if($per_page === false){
            $page = new \Gy_Library\GyPage($count);
        } else {
            $page = new \Gy_Library\GyPage($count, $per_page);
        }
        $data_list = $news_model->getListForPage($map, $page->nowPage, $page->listRows, '');
        foreach ($data_list as &$item){
            $item['vehicle_desc'] = D('VehicleNumber')->where(['id'=>$item['vehicle_id']])->getField('number');
            $item['shop_desc'] = D('CarShop')->where(['id'=>$item['shop_id']])->getField('name');
        }
        $builder = new \Qscmf\Builder\ListBuilder();
        $builder->setMetaTitle('抽奖用户')  // 设置页面标题
            ->addTopButton('addnew')   // 添加新增按钮;
            ->addTopButton('delete')   // 添加删除按钮
            ->addTopButton('save', ['title'=>'保存排序'])   // 添加删除按钮
            ->setNIDByNode(MODULE_NAME,CONTROLLER_NAME,__FUNCTION__)
            ->addTableColumn('name', '客户姓名')
            ->addTableColumn('phone', '手机号')
            ->addTableColumn('code', '身份证号码')
            ->addTableColumn('number', '指标编码')
            ->addTableColumn('vehicle_desc', '车辆型号')
            ->addTableColumn('shop_desc', '购车门店')
            ->addTableColumn('right_button', '操作', 'btn')
            ->setTableDataList($data_list)     // 数据列表
            ->setTableDataPage($page->show())  // 数据列表分页
            ->addRightButton('edit')           // 添加编辑按钮
            ->addRightButton('delete')         // 添加删除按钮
            ->display();
    }
    public function add(){
        parent::addPost();
        $builder = new \Qscmf\Builder\FormBuilder();
        $info = ["status"=>1];
        $builder->setMetaTitle('新增抽奖用户'); //设置页面标题
        $this->formBuilderPublic($builder);
        $builder->setFormData($info)->display();
    }
    public function edit($id){
        parent::editPost();
        $info = D($this->dbname)->getOne($id);
        $builder = new \Qscmf\Builder\FormBuilder();
        $builder->setMetaTitle('编辑抽奖用户');
        $builder->addFormItem('id', 'hidden', 'ID');
        $this->formBuilderPublic($builder);
        $builder->setFormData($info)->display();
    }
    public function formBuilderPublic(&$builder){
        $builder->setNIDByNode(MODULE_NAME,CONTROLLER_NAME,'index')
            ->addFormItem('name', 'text', '客户姓名')
            ->addFormItem('phone', 'text', '手机号')
            ->addFormItem('code', 'text', '身份证号码')
            ->addFormItem('number', 'text', '指标编码')
            ->addFormItem('vehicle_id', 'select', '车辆型号','',D('VehicleNumber')->getParentOptions("id","number"))
            ->addFormItem('shop_id', 'select', '购车门店','',D('CarShop')->getParentOptions("id","name"));
    }
}







































